package com.example.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

@Slf4j
@Component
@RequiredArgsConstructor
public class ApplicationRunner implements CommandLineRunner {

    private final Environment env;

    @Override
    public void run(String... args) throws Exception {
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port", "8080");
        String path = env.getProperty("server.servlet.context-path", "");
        String profilesActive = String.join(",", env.getActiveProfiles());

        log.info("""

                        ----------------------------------------------------------
                        \t应用已启动! 相关接口如下:
                        \tLocal访问网址: \thttp://localhost:{}{}
                        \tExternal访问网址: \thttp://{}:{}{}
                        \tKnife4j文档: \thttp://{}:{}{}/doc.html
                        \t当前使用的环境: \t{}
                        ----------------------------------------------------------""",
                port, path,
                ip, port, path,
                ip, port, path,
                profilesActive);
    }
} 